﻿using System;
using System.Collections.Generic;
using Mads.CoreDomain.Enumerations;
using System.Runtime.Serialization;

namespace Mads.CoreDomain
{
  /// <summary>
  /// Represents a single route in timetable.
  /// </summary>
  [DataContract]
  public class Route : VersionedKeyAbstraction
  {
    #region public properties
    /// <summary>
    /// Route seatsNumber in timetable.
    /// </summary>
    [DataMember]
    public uint LogicalID { get; set; }

    /// <summary>
    /// Speed type of the train: fast or passenger.
    /// </summary>
    [DataMember]
    public SpeedType SpeedType { get; set; }

    /// <summary>
    /// How often the train goes.
    /// If NDays is selected, amount of days is stored in Days property.
    /// </summary>
    public Regularity Regularity { get; set; }

    /// <summary>
    /// Every N days train leaves.
    /// </summary>
    public byte? Days { get; set; }

    /// <summary>
    /// Time of this route departure.
    /// </summary>
    public TimeSpan DefaultDeparture { get; set; }

    /// <summary>
    /// Ticket price will be multiplied by this coefficient.
    /// </summary>
    public float PriceMultiplier { get; set; }

    /// <summary>
    /// Stops that this route makes.
    /// </summary>
    public IEnumerable<RouteStop> Stops { get; private set; }

    /// <summary>
    /// Train cars for this route.
    /// </summary>
    public IEnumerable<Car> Cars { get; private set; }

    /// <summary>
    /// Races following this route.
    /// </summary>
    public IEnumerable<Race> Races { get; private set; }
    #endregion

    public Route(
      uint logicalID, SpeedType speedType, Regularity regularity,
      uint defaultDepartureMinutes,
      byte? days, float priceMultiplier)
      : base()
    {
      if (defaultDepartureMinutes >= 24 * 60)
      {
        throw new ArgumentException("defaultDepartureMinutes");
      }
      if (priceMultiplier <= 0)
      {
        throw new ArgumentException("priceMultiplier");
      }

      LogicalID = logicalID;
      SpeedType = speedType;
      Regularity = regularity;
      Days = days;
      DefaultDeparture = new TimeSpan(0, (int)defaultDepartureMinutes, 0);
      PriceMultiplier = priceMultiplier;
    }
    public Route(uint id)
    {
      ID = id;
    }
  }
}